
(require 'cl)

(when (>= emacs-major-version 24)
  (require 'package)
  (package-initialize)
  ;;(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
  (setq package-archives '(("gnu"   . "http://elpa.emacs-china.org/gnu/")
                           ("melpa" . "http://elpa.emacs-china.org/melpa/")))
  )

;;add whatever packages you want here  == hungry-delete , swiper , counsel , smartparens
(defvar zilongshanren/packages '(
				 company
				 monokai-theme
				 swiper
				 counsel
				 hungry-delete
				 smartparens
				 evil
				 evil-leader
				 window-numbering
				 which-key
				 evil-nerd-commenter
				 use-package
				 )  "Default packages")
(setq package-selected-packages zilongshanren/packages)



(defun zilongshanren/packages-installed-p ()
  (loop for pkg in zilongshanren/packages
        when (not (package-installed-p pkg)) do (return nil)
        finally (return t)))

(unless (zilongshanren/packages-installed-p)
  (message "%s" "Refreshing package database...")
  (package-refresh-contents)
  (dolist (pkg zilongshanren/packages)
    (when (not (package-installed-p pkg))
      (package-install pkg))))

;; 'hungry-delete
(require 'hungry-delete)
(global-hungry-delete-mode)

;; smartparens
(require 'smartparens-config)
(smartparens-global-mode t)

;;company mode
(global-company-mode t)

;;swiper
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
;; enable this if you want `swiper' to use it
;; (setq search-default-mode #'char-fold-to-regexp)

;;monokai-theme
(load-theme 'monokai t)

(evil-mode t)

(global-evil-leader-mode)
(evil-leader/set-key
  "ff" 'find-file
  "bb" 'switch-to-buffer
  "0"  'select-window-0
  "1"  'select-window-1
  "2"  'select-window-2
  "3"  'select-window-3
  "SPC" 'other-window
  "x"  'delete-window
  "w/" 'split-window-right
  "w-" 'split-window-below
  ":"  'counsel-M-x
  ;;"wM" 'delete-other-windows
  "o" 'delete-other-windows
  "k" 'kill-buffer
  "r" 'recentf-open-files
  "j" 'dired-jump
  )

(window-numbering-mode t)

(which-key-mode)

;; Emacs key bindings
(global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
(global-set-key (kbd "C-c l") 'evilnc-quick-comment-or-uncomment-to-the-line)
(global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
(global-set-key (kbd "C-c p") 'evilnc-comment-or-uncomment-paragraphs)


(provide 'init-packages)
